

//父类

//构造函数
function DragBox(id){
	if( id ){
		this.box = document.getElementById(id);
		var that = this;
		this.box.onmousedown = function(e){	//鼠标按下，开始运动
			var evt = e || event;
			e.preventDefault();
			that.startMove( evt.pageX, evt.pageY );
		}
	}
}

DragBox.prototype.startMove = function(x,y){//开始拖动
	this.disX = x - this.box.offsetLeft;
	this.disY = y - this.box.offsetTop;
	
	var that = this;
	document.onmousemove = function(e){		//鼠标移动
		var evt = e || event;
		that.moving( evt.pageX, evt.pageY );
	}
	document.onmouseup = function(){		//鼠标松开
		that.stopMove();
	}
}

DragBox.prototype.moving = function(x,y){		//拖动
	this.box.style.left = x - this.disX + 'px';
	this.box.style.top = y- this.disY + 'px';
}

DragBox.prototype.stopMove = function(){	//停止拖动
	document.onmousemove = document.onmouseup = null;
}
